package com.winhxd.b2c.common.feign.order;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.winhxd.b2c.common.constant.BusinessCode;
import com.winhxd.b2c.common.constant.ServiceName;
import com.winhxd.b2c.common.domain.PagedList;
import com.winhxd.b2c.common.domain.ResponseResult;
import com.winhxd.b2c.common.domain.order.condition.OrderUserManagementQueryCondition;
import com.winhxd.b2c.common.domain.order.vo.OrderInfoDetail4UserManagementVO;

import feign.hystrix.FallbackFactory;

/**
 * 用户管理中的订单信息
 * @author suhaochan
 * @date 2019/1/7 20:10:18
 */
@FeignClient(value = ServiceName.ORDER_SERVICE, fallbackFactory = OrderUserManagementClientFallback.class)
public interface OrderUserManagementClient {
	
	/**
	 * @author suhaochan
	 * @date 2019/1/7 20:10:18
	 * @Description 查询分销商订单列表
	 * @param condition
	 * @return
	 */
	@RequestMapping(value = "/order/4131/v1/findDistributorOrder/", method = RequestMethod.POST)
    ResponseResult<PagedList<OrderInfoDetail4UserManagementVO>> findDistributorOrder(@RequestBody OrderUserManagementQueryCondition condition);

	/**
	 * @author suhaochan
	 * @date 2019/1/7 20:11:47
	 * @Description 查询分销商会员订单列表
	 * @param condition
	 * @return
	 */
	@RequestMapping(value = "/order/4132/v1/findDistributorMemberOrder/", method = RequestMethod.POST)
    ResponseResult<PagedList<OrderInfoDetail4UserManagementVO>> findDistributorMemberOrder(@RequestBody OrderUserManagementQueryCondition condition);

	/**
	 * @author suhaochan
	 * @date 2019/1/7 20:14:01
	 * @Description 查询会员订单列表
	 * @param condition
	 * @return
	 */
	@RequestMapping(value = "/order/4133/v1/findMemberOrder/", method = RequestMethod.POST)
    ResponseResult<PagedList<OrderInfoDetail4UserManagementVO>> findMemberOrder(@RequestBody OrderUserManagementQueryCondition condition);

}

@Component
class OrderUserManagementClientFallback implements OrderUserManagementClient, FallbackFactory<OrderUserManagementClient> {
    private static final Logger logger = LoggerFactory.getLogger(OrderUserManagementClientFallback.class);
    private Throwable throwable;

    public OrderUserManagementClientFallback() {
    }

    private OrderUserManagementClientFallback(Throwable throwable) {
        this.throwable = throwable;
    }

	@Override
	public OrderUserManagementClient create(Throwable cause) {
		 return new OrderUserManagementClientFallback(throwable);
	}

	@Override
	public ResponseResult<PagedList<OrderInfoDetail4UserManagementVO>> findDistributorOrder(
			OrderUserManagementQueryCondition condition) {
		 logger.error("OrderUserManagementClientFallback -> findDistributorOrder", throwable);
	     return new ResponseResult<>(BusinessCode.CODE_1001);
	}

	@Override
	public ResponseResult<PagedList<OrderInfoDetail4UserManagementVO>> findDistributorMemberOrder(
			OrderUserManagementQueryCondition condition) {
		logger.error("OrderUserManagementClientFallback -> findDistributorMemberOrder", throwable);
	    return new ResponseResult<>(BusinessCode.CODE_1001);
	}

	@Override
	public ResponseResult<PagedList<OrderInfoDetail4UserManagementVO>> findMemberOrder(
			OrderUserManagementQueryCondition condition) {
		logger.error("OrderUserManagementClientFallback -> findMemberOrder", throwable);
	    return new ResponseResult<>(BusinessCode.CODE_1001);
	}
}